package me.goldze.mvvmhabit.binding.viewadapter.checkbox;

import android.view.View;
import android.widget.CheckBox;

import androidx.databinding.BindingAdapter;

import me.goldze.mvvmhabit.binding.command.BindingCommand;

/**
 * Created by goldze on 2017/6/18.
 */
public class ViewAdapter {
    @BindingAdapter(value = {"onCheckedChangedCommand"}, requireAll = false)
    public static void onCheckedChangedCommand(final CheckBox checkBox, final BindingCommand<Boolean> bindingCommand) {
        checkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CheckBox cb = (CheckBox) v;
                if (cb != null) {
                    bindingCommand.execute(cb.isChecked());
                }
            }
        });
    }
}
